package com.cndw.kungfu.model.battle;

import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.domain.Pet;
import com.cndw.kungfu.domain.SkillMode;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.battlevo.BattlePetVO;

/**
 * 宠物战斗对象
 * 
 * @author fantadust
 * @date 2011-4-28 下午02:50:33
 */
public class FighterPet extends FighterBase implements Fighter,ISkill {

	private Pet sourceObject;

	public FighterPet(Pet pet) {
		sourceObject = pet;
	}

	public FighterPet(Pet pet, int buffCoefficient) {
		sourceObject = pet;
		this.buffCoefficient = buffCoefficient;
		if (buffCoefficient != 0) {
			fixAttack = NumberProcesser.percentOnlyAddValue(sourceObject.getAttack(), buffCoefficient);
			fixDefense = NumberProcesser.percentOnlyAddValue(sourceObject.getDefense(), buffCoefficient);
			fixHit = NumberProcesser.percentOnlyAddValue(sourceObject.getHit(), buffCoefficient);
			fixDodge = NumberProcesser.percentOnlyAddValue(sourceObject.getDodge(), buffCoefficient);
			fixCrit = NumberProcesser.percentOnlyAddValue(sourceObject.getCrit(), buffCoefficient);
			fixTough = NumberProcesser.percentOnlyAddValue(sourceObject.getTough(), buffCoefficient);
		}

	}

	@Override
	public long getUniqueId() {
		return sourceObject.getId();
	}

	@Override
	public String getName() {
		return sourceObject.getName();
	}

	@Override
	public int getHp() {
		return sourceObject.getHp();
	}

	@Override
	public int getMp() {
		return sourceObject.getMp();
	}

	@Override
	public int getMaxHp() {
		return sourceObject.getMaxHp();
	}

	@Override
	public int getMaxMp() {
		return sourceObject.getMaxMp();
	}

	@Override
	public int getLevel() {
		return sourceObject.getLevel();
	}

	@Override
	public int getAttack() {
		return sourceObject.getAttack() + fixAttack;
	}

	@Override
	public int getDefense() {
		return sourceObject.getDefense() + fixDefense;
	}

	@Override
	public int getHit() {
		return sourceObject.getHit() + fixHit;
	}

	@Override
	public int getDodge() {
		return sourceObject.getDodge() + fixDodge;
	}

	@Override
	public int getCrit() {
		return sourceObject.getCrit() + fixCrit;
	}

	@Override
	public int getTough() {
		return sourceObject.getTough() + fixTough;
	}

	@Override
	public Pet getSourceObject() {
		return sourceObject;
	}

	/**
	 * 重写获取攻速的方法
	 */
	@Override
	public int getSpeed() {
		return sourceObject.getSpeed();
	}

	/**
	 * 设置血量
	 * 
	 * @param alter
	 */
	@Override
	public synchronized void alterHp(int alter) {
		int newHp = NumberProcesser.between(alter + getHp(), 0, getMaxHp());
		sourceObject.setHp(newHp);
	}

	/**
	 * 设置魔法量
	 * 
	 * @param alter
	 */
	@Override
	public synchronized void alterMp(int alter) {
		int newMp = NumberProcesser.between(alter + getMp(), 0, getMaxMp());
		sourceObject.setMp(newMp);
	}

	@Override
	public int getHurtAdd() {
		return 0;
	}

	@Override
	public int getHurtRemove() {
		return 0;
	}

	@Override
	public int getHurtReflex() {
		return 0;
	}

	@Override
	public int getHurtAbsorb() {
		return 0;
	}

	@Override
	public int getCritAdd() {
		return 0;
	}

	@Override
	public int getSceneId() {
		return 0;
	}

	@Override
	public BattlePetVO toVO() {
		return sourceObject.toTeamPetVO();
	}

	@Override
	public int getCurrentSkillId(int nowstep) {
		if (sourceObject.getSkillIds() != null && sourceObject.getSkillIds().length > 0) {
			try {
				int maxSize = sourceObject.getSkillIds().length;
				int rateTimes = maxSize > ConstantsModel.petSkillGirdFree ? 2 : 1;
				for (int i = 0; i < rateTimes; i++) {
					int indexId = maxSize == 1 ? 1 : NumberProcesser.mtRand(maxSize);
					int eId = sourceObject.getSkillIds()[indexId - 1];
					SkillMode skillMode = Context.getSkillServer().getSkillMode(eId);
					if (skillMode != null && skillMode.getEffectValue() > 0) {
						if (NumberProcesser.isWinning(skillMode.getBuffRate())) {
							if (getMp() >= skillMode.getConstMp()) {
								return eId;
							} else {
								continue;
							}
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return 0;
	}

	@Override
	public int getScoreCHK() {
		return 0;
	}

	@Override
	public int getHurtCoffAdd() {
		return 0;
	}

	@Override
	public int getHurtCoffRemove() {
		return 0;
	}

}
